Javascript replace space with regex


\s : means "one space"

\s+ : means "one or more spaces"

let stringWithSpace = '  A B  C   D EF ';

console.log(str.replace(/\s/g, '#'));                                
// ##A#B##C###D#EF# => means one space replace by one #;

console.log(str.replace(/\s+/g, '#'));                             
// #A#B#C#D#EF#  => means one or more spaces, all replace by #;
#javascript #replace #RegEx






你可能感興趣的文章

如何使用 Python Tkinter 製作 GUI 應用程式入門教學

如何使用 Python Tkinter 製作 GUI 應用程式入門教學

Vite系列#安裝外部套件 - Vue Axios

Vite系列#安裝外部套件 - Vue Axios

RESTful API 是什麼?

RESTful API 是什麼?






留言討論